#include <string>
#include "ssdb.h"
#include "log.h"

int main(int argc, char **argv){
	std::string work_dir = "/tmp/a";
	ssdb::Options opt;
	opt.compression = "no";

	auto ssdb = ssdb::SSDB::open(opt, work_dir);
	if(!ssdb){
		log_fatal("could not open work_dir: %s", work_dir.c_str());
		fprintf(stderr, "could not open work_dir: %s\n", work_dir.c_str());
		exit(1);
	}
	std::string key, val;
	key = "a";
	
	val.append(1024 * 1024, 'a');
	ssdb->raw_set("tmp", val);
	ssdb->compact();

	uint64_t size;
	size = ssdb->size();
	printf("dbsize: %ld\n", size);


	ssdb->get(key, &val);
	int num = ssdb::str_to_int(val) + 1;
	ssdb->set(key, ssdb::str(num));
	ssdb->get(key, &val);
	
	printf("%s\n", val.c_str());

  std::vector<std::string> keys;
  ssdb->key_range(&keys);
  for (auto& key: keys) {
    printf("key[%ld]:%s\n", key.length(), key.c_str());
  }
}
